﻿//统一文件为utf-8编码编译
#pragma execution_character_set("utf-8")
///////////////////////////////////////////////////////////////////////////
// 文件名:     savepathdialog.cpp
// 描述:
// 作者:      颜磊
// 创建工程：   SpaceClear
// 创建时间:   2024-07-24 15:31
///////////////////////////////////////////////////////////////////////////
#include "savepathdialog.h"
#include "ui_savepathdialog.h"

#include <QFileDialog>

SavePathDialog::SavePathDialog(int saveT,ClearPath *clearPath,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SavePathDialog)
{
    ui->setupUi(this);
    saveType = saveT;
    setWindowTitle(saveType == 0 ? QString("添加") :  QString("修改") );
    if(saveType == 1){
        upId = clearPath->id;
        ui->path->setText(clearPath->path);
        ui->filter_suffix->setText(clearPath->filter_suffix);
        ui->cascade->setChecked(clearPath->cascade);
        ui->elapsed->setValue(clearPath->elapsed);
        ui->data_number_enable->setChecked(clearPath->data_number_enable);
        ui->data_number->setValue(clearPath->data_number);
        ui->unit_option->setCurrentIndex(clearPath->unit_option);
        ui->time_enable->setChecked(clearPath->time_enable);
        ui->time_option->setCurrentIndex(clearPath->time_option);
        ui->enable->setChecked(clearPath->enable);
    }
}

SavePathDialog::~SavePathDialog()
{
    delete ui;
}

void SavePathDialog::on_saveBtn_clicked()
{
    ClearPath clearPath;
    clearPath.id = upId;
    clearPath.setPath(ui->path->text().toStdString());
    clearPath.setFilterSuffix(ui->filter_suffix->text().toStdString());
    clearPath.cascade = ui->cascade->isChecked();
    clearPath.elapsed = ui->elapsed->value();
    clearPath.data_number_enable = ui->data_number_enable->isChecked();
    clearPath.data_number = ui->data_number->value();
    clearPath.unit_option = ui->unit_option->currentIndex();
    clearPath.time_enable = ui->time_enable->isChecked();
    clearPath.time_option = ui->time_option->currentIndex();
    clearPath.enable = ui->enable->isChecked();
    emit signal_saveClearPath(saveType,clearPath);
    QDialog::accept();
}

void SavePathDialog::on_cancelBtn_clicked()
{
    QDialog::reject();
}

void SavePathDialog::on_selBtn_clicked()
{
    QString selectDir = QFileDialog::getExistingDirectory(this,QString("选择文件夹"),ui->path->text());
    if(!selectDir.isEmpty()){
        ui->path->setText(selectDir);
    }
}
